/*Copyright (C) 2009 - 2011 MASSART GAUTHIER

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../headers.h"

void hanoi_afficher_tours(long lignes_colonnes[10][3], long choix, long deplacements, long type, char message[100]) {
	long x = 0, y = 0, j = 0;
	short n = 0;

	CSLP_ColorText(CT);
	mvaddstr(7, 0, "Déplacement\n    n°");
	CSLP_ColorText(COLOR_RED);
	printw("%ld", deplacements);
	CSLP_ColorText(COLOR_WHITE);

	x = 5, y = x_begin_center(98);

	move(x, y);
	x++;

	while(j != 24) {
		move(x, y);

		for(n = 0 ; n < 3 ; n++) {

			afficher_char_fullblock(1, COLOR_WHITE);

			addstr("                               ");
		}

		afficher_char_fullblock(1, COLOR_WHITE);

		x++;
		j++;
	}

	move(x, y);
	CSLP_Color(COLOR_WHITE, COLOR_BLACK);

	for(n = 0 ; n < 3 ; n++) {
		if(choix - 1 == n) {
			if(type == 1)
				CSLP_Color(COLOR_YELLOW, COLOR_CYAN);
			else if(type == 2)
				CSLP_Color(COLOR_BLUE, COLOR_MAGENTA);
		}

		afficher_char_fullblock(1, COLOR_WHITE);

		if(choix - 1 != n) {
			CSLP_Color(COLOR_WHITE, COLOR_BLACK);
		}

		printw("           COLONNE %d           ", n + 1);
	}

	afficher_char_fullblock(1, COLOR_WHITE);

	CSLP_Color(COLOR_WHITE, COLOR_BLACK);

	j = 0;

	if(choix == 0)
		CSLP_Color(COLOR_WHITE, COLOR_CYAN);

	mvaddstr(35, 5, "┌─────────┐");
	mvaddstr(36, 5, "│ QUITTER │");
	mvaddstr(37, 5, "└─────────┘");
	CSLP_Color(COLOR_WHITE, COLOR_BLACK);

	hanoi_afficher_cube(lignes_colonnes);

	if(type < 3)
		CSLP_ColorText(COLOR_CYAN);
	else
		CSLP_ColorText(COLOR_RED);

	hanoi_afficher_message(message);

	refresh();
}

void hanoi_afficher_message(char message[100]) {
	save_cursor_pos();
	move(38, 0);
	clrtoeol();
	afficher_centre(message);
	restore_cursor_pos();
	CSLP_ColorText(COLOR_WHITE);
}

void hanoi_afficher_cube(long lignes_colonnes[10][3]) {
	const long colonne[4] = {48, 80, 112}, base = 30;
	long i = 0, j = 0, k = 0, x = 0, y = 0, taille = 0;

	while(i != 10) {
		while(j != 3) {

			taille = lignes_colonnes[i][j];

			if(taille != 0) {
				y = ((colonne[j] + (colonne[j] - 30) - taille * 2) / 2) - 5;
				x = base - i * 2 - 1;
				mvaddstr(x, y, "▒▓███");
				k = 0;

				while(k != taille) {
					afficher_char_fullblock(2, COLOR_WHITE);
					k++;
				}

				addstr("██▓▒");

				mvaddstr(x - 1, y, "▒▓███");
				k = 0;

				while(k != taille) {
					afficher_char_fullblock(2, COLOR_WHITE);
					k++;
				}

				addstr("██▓▒");

			}

			j++;
		}

		i++;
		j = 0;
	}
}
